var express = require('express');
var router = express.Router();
var URL = require('url');
var User = require('./user')

/* GET users listing. */
router.get('/', function(req, res, next) {
    res.send('respond with a resource');
});

var user = new User();
// 默认灯关
user.ledstatus = 0;

// 查询灯状态接口
router.get('/getLedStatus', function(req, res, next) {
    var response = { status: 200, data: user };
    console.log('查询成功:' + user.ledstatus)
        // console.log(req)
    res.send(JSON.stringify(response));
})

// 开灯接口
router.get('/openLed', function(req, res, next) {
        user.ledstatus = 1;
        var response = { status: 200, data: user };
        console.log('开灯啦:' + user.ledstatus)
        res.send(JSON.stringify(response));
    })
    // 关灯接口
router.get('/closeLed', function(req, res, next) {
    user.ledstatus = 0;
    var response = { status: 200, data: user };
    console.log('关灯啦:' + user.ledstatus)
    res.send(JSON.stringify(response));
})

module.exports = router;